#pragma  once


#ifndef UPD_SERVER_H
#define UPD_SERVER_H
#include <string>
#include <vector>
#include <windows.h>
#include <cnet.h>

using namespace std;
#define  CMD_COLNBIP  "COLIP"
#define  AGENTIP  "AIP"
#define  CNET_HEAD  "<CNET>"

#define UDP_SERVER_PORT 7001
#define UDP_LISTEN_PORT 7002
#define UDP_RXBUF_LEN 512


typedef enum
{
	Msg_CNET,
	Msg_AgentIP,
	Msg_COLLIP,
	Msg_error
}MessageType;



class UDP_server 
{
public:
	int UDP_server_init();
	int  UDP_server_start();
	static void onreceive();
	void broadCastCMD(string cmd);
	static DWORD WINAPI  UDP_recv(void * para);
	static UDP_server * getGALUDPserver();
	int fillNeighbourIP();
	static vector<string> * GetNBContainer(); 

	static void handleCOllIP();
	static void handleAgentIP();
	static MessageType getMsgTypeUDP();
 

	int sendMsg(string MsgtoSend, string destIp);
    
private:

	static char udp_rxbuff[UDP_RXBUF_LEN];
	static char udp_txbuff[UDP_RXBUF_LEN];
	static  UDP_server *   g_pudpServer;
	static vector<string> neighbourIP;
	static  SOCKADDR_IN saUdpServ;
};


#endif
